﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using DlhSoft.Windows.Data;

namespace luanvanFinal
{
    /// <summary>
    /// Interaction logic for wdGantt.xaml
    /// </summary>
    public partial class wdGantt : Window
    {
        private String message;
        public wdGantt()
        {
            
            InitializeComponent();
            addItems(message);
        }
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        public void addItems(String pro)
        {
            clsProject project = new clsProject();
            reqTrace reqTrace = new reqTrace();
            int idProject = Convert.ToInt32(project.getIdFromName(pro));
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            String strSQL = "select * from reqTrace where idPro = '"+idProject+"' ";
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string span = dt.Rows[i][4].ToString();
                TimeSpan effort = new TimeSpan(int.Parse(span.Split(':')[0]),    // hours
                               0,    // minutes
                               0);
                string span1 = dt.Rows[i][5].ToString();
                TimeSpan comEffort = new TimeSpan(int.Parse(span1.Split(':')[0]),    // hours
                               0,    // minutes
                               0);
                TaskItem a = new TaskItem();
                a.Content = dt.Rows[i][1].ToString();
                a.Indentation = 0;
                a.Start = Convert.ToDateTime(dt.Rows[i][3].ToString());
                a.Effort = effort;
                a.CompletedEffort = comEffort;
                //a.CompletedEffort=Cpeffort ;
                a.Cost = Convert.ToInt32(dt.Rows[i][7].ToString());                
                a.AssignmentsString = dt.Rows[i][6].ToString();
                gChart.Items.Add(a);
            }
            ketnoi.closeConnection();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            addItems(message);
        }
    }
}
